
import java.util.Arrays;

public class Solution {
    public boolean verifyPostorder(int[] postorder) {
        int len = postorder.length;
        if (len == 0) return true;
        int i = 0;
        while (postorder[i] < postorder[len - 1]) {
            i++;
        }
        int index = i;
        while (postorder[i] > postorder[len - 1]) {
            i++;
        }
        if (i < len - 1) return false;
        return verifyPostorder(Arrays.copyOfRange(postorder, 0, index)) && verifyPostorder(Arrays.copyOfRange(postorder,index, len -1 ));
    }
}
